﻿
@{
    ViewData["Title"] = "DifferenceIndex";
    Layout = null;
}

<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />


    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
            background-color: #f9f9f9;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: left;
        }

        th {
            background-color: #f4f4f4;
            font-weight: bold;
        }

        .toolbar {
            margin-bottom: 10px;
        }

            .toolbar input[type="text"] {
                margin-right: 10px;
            }

            .toolbar button {
                margin-right: 5px;
                background-color: #007bff;
                color: white;
                border: none;
                padding: 8px 12px;
                cursor: pointer;
                border-radius: 4px;
            }

                .toolbar button:hover {
                    background-color: #0056b3;
                }

        .actions button {
            background-color: #dc3545;
            color: white;
            border: none;
            padding: 5px 10px;
            cursor: pointer;
            border-radius: 4px;
        }

            .actions button:hover {
                background-color: #c82333;
            }
    </style>

<body>

    <h2>盘点差异</h2>
    <br />
    <div class="toolbar">
        <label>中文全称: <input type="text" id="stocker"></label>
        <button id="searchButton">查询</button>
        <button id="addButton">录入</button>
       
     
    </div>

    <table class="layui-hide" id="mainData" lay-filter="mainData" style="margin-top: 10px;margin-left: 20px">
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-orange layui-btn-xs" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-orange layui-btn-xs" lay-event="update">编辑</a>
    </script>

    <script src="~/libs/jquery/jquery.js"></script>
    <script src="~/libs/layui-v2.5.6/layui/layui.all.js"></script>

    <script>
        layui.use(['table', 'form', 'layer'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;

            // 渲染数据表格
            function showData() {
                table.render({
                    elem: '#mainData',
                    url: '/Difference/GetDifference',
                    page: true,
                    limit: 10,
                    limits: [10, 20, 30],
                    cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'stocker', title: '盘点人', width: 120, align: 'center' },
                        { field: 'stockDate', title: '盘点日期', width: 120, align: 'center' },
                        { field: 'storage', title: '储位', width: 120, align: 'center' },
                        { field: 'tray', title: '托盘', width: 120, align: 'center' },
                        { field: 'commodityCode', title: '商品编码', width: 120, align: 'center' },
                        { field: 'commodityName', title: '商品名称', width: 120, align: 'center' },
                        { field: 'accounts', title: '账目数量', width: 120, align: 'center' },                    
                        { field: 'protructDate', title: '生产日期', width: 120, align: 'center' },
                        { field: 'stockNum', title: '盘点数量', width: 120, align: 'center' },
                        { field: 'owner', title: '货主', width: 120, align: 'center' },
                        { field: 'ownerCode', title: '货主编码', width: 120, align: 'center' },
                        {
                            field: 'stockStatus',
                            title: '单据状态',
                            templet: function (d) {
                                return d.stockStatus ? '已完成' : '未完成';
                            },
                            width: 110,
                            key: 'stockStatus' // 使用 key 来标识这一列
                        },
                        { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center' }
                    ]],
                    where: {
                        stocker: $("#stocker").val().toString(),
                    },
                    parseData: function (res) {
                        console.log(res);
                        return {
                            code: res.code,
                            count: res.data.result.pageCount,
                            data: res.data.result.queryable
                        };
                    },
                });
            }

            showData();

            // 监听工具条
            table.on('tool(mainData)', function (obj) {
                var data = obj.data; // 获取当前行数据
                if (obj.event === 'delete') {
                    layer.confirm('确定要删除吗？', {
                        btn: ['确定', '取消'] // 按钮
                    }, function () {
                        $.ajax({
                            url: '/Difference/DifferenceDelete',
                            type: 'post',
                            data: {
                                id: data.id
                            },
                            success: function (res) {
                                if (res.msg == '删除成功') {
                                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                        showData(); // 刷新表格
                                    });
                                } else {
                                    layer.msg(res.msg, { icon: 2, time: 1000 });
                                }
                            }
                        });
                    }, function () {
                        layer.msg('已取消', { icon: 1, time: 1000 });
                    });
                }
                  if (obj.event === 'update') {
                // iframe层
                layer.open({
                    type: 2,
                    title: '修改数据',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['600px', '60%'],
                    content: '/Difference/DifferenceUpdateIndex?id=' + data.id, // iframe的src
                    end: function () {
                        // iframe层关闭后刷新页面
                        location.reload(); // 刷新页面
                    }
                });
            }
            });

            // 查询
            $("#searchButton").on("click", function () {
                showData();
            });

            // 录入
            $("#addButton").on("click", function () {
                layer.open({
                    type: 2,
                    area: ['800px', '70%'],
                    title: '录入信息',
                    shade: 0.6,
                    shadeClose: true,
                    maxmin: true,
                    anim: 0,
                    content: '/Difference/DifferenceAddIndex',
                    end: function () {
                        showData(); // 刷新表格
                    }
                });
            });



        });
    </script>

</body>







